package erfgame.core.world.generator.terrain;

import java.util.ArrayList;
import java.util.List;


import erfgame.core.BaseCompositeOperation;
import erfgame.core.Operation;
import erfgame.core.world.World;
import erfgame.core.world.WorldGenerationParameters;
import erfgame.core.world.WorldGenerator;

public class CompositeWorldGenerator implements WorldGenerator {

	private List<WorldGenerator> children;
	
	public CompositeWorldGenerator( List<WorldGenerator> children ) {
		this.children = children;
	}
	
	public CompositeWorldGenerator() {
		this.children = new ArrayList<WorldGenerator>();
	}
	
	public void addChild( WorldGenerator child ) {
		this.children.add( child );
	}
	
	public Operation<Void, RuntimeException> generate(World world, WorldGenerationParameters parameters) {
		ArrayList<Operation<Void,RuntimeException>> childOperations;
		childOperations = new ArrayList<Operation<Void,RuntimeException>>(children.size());
		
		for( int i=0; i<children.size(); i++ ) {
			WorldGenerator child;
			child = children.get(i);
			Operation<Void,RuntimeException> childOperation;
			childOperation = child.generate(world, parameters);
			childOperations.add(childOperation);
		}
		
		return new BaseCompositeOperation<Void, Void, RuntimeException>(childOperations);
	}
	
}
